
 begintownscript;

 variables;

 int i,j,k,r1,choice;

 body;

 beginstate INIT_STATE;

	set_name(8,"Vitendo");
	set_name(9,"Horendo");
	set_name(10,"Rebel");
	set_name(11,"Rebel");
	set_name(12,"Rebel");
	set_name(13,"Rebel");
	set_name(14,"Rebel");
	set_name(15,"Rebel");


	set_level(6,30);
	set_level(8,30);
	set_level(10,25);

	if (get_flag(13,2) == 2)
		set_flag(13,2,1);

	if (get_flag(13,4) == 2)
		set_flag(13,4,1);

	if ((get_flag(17,17) >= 2) && (get_flag(17,9) == 1)) {
		erase_char(6);
		erase_char(7);
		erase_char(8);
		erase_char(9);
		erase_char(10);
		erase_char(11);
		erase_char(12);
		erase_char(13);
		erase_char(14);
		erase_char(15);
		set_terrain(16,28,0);
		set_terrain(16,23,0);
}

	set_crime_tolerance(1);
break;

 beginstate START_STATE;

	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(9,"I'm a wizard!");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(9,"ZAP! BOOM!");

	if ((char_ok(9) == FALSE) && (get_flag(13,12) == 1)) {
		make_town_hostile();
		relocate_character(8,37,23);
		message_dialog("Vitendo heard the fighting and ran towards you, too late. His brother is dead and he is not happy. _What did you do!? You killed him! You damn fool!_ With that he attacks you.","");
		set_flag(13,12,2);
}
break;

 beginstate EXIT_STATE;

break;

 beginstate 11;
	reset_dialog();
	add_dialog_str(0,"You find a lever labeled _Rock_. Although you have no idea why the lever is named like that, you could easily pull the lever. Will you?",0);
	add_dialog_choice(0,"Pull the Lever.");
	add_dialog_choice(1,"Ignore it.");
	choice = run_dialog(1);

	if (choice == 1) {
		inc_flag(13,0,1);
		inc_flag(13,7,1);
		swap_terrain(7,34,374,375);
		play_sound(76);

	if ((get_flag(13,0) == 7) && (get_flag(13,1) == 4) && (get_flag(13,7) == 1)) {
		play_sound(45);
		set_terrain(9,31,0);
		force_instant_terrain_redraw();
		set_flag(13,0,0);
}
}
break;

 beginstate 12;
	reset_dialog();
	add_dialog_str(0,"You find a lever labeled _Scissors_. Although you have no idea why the lever is named like that, you could easily pull the lever. Will you?",0);
	add_dialog_choice(0,"Pull the Lever.");
	add_dialog_choice(1,"Ignore it.");
	choice = run_dialog(1);

	if (choice == 1) {
		inc_flag(13,0,2);
		inc_flag(13,1,3);
		set_flag(13,7,0);
		swap_terrain(9,34,374,375);
		play_sound(76);
}
break;

 beginstate 10;
	reset_dialog();
	add_dialog_str(0,"You find a lever labeled _Paper_. Although you have no idea why the lever is named like that, you could easily pull the lever. Will you?",0);
	add_dialog_choice(0,"Pull the Lever.");
	add_dialog_choice(1,"Ignore it.");
	choice = run_dialog(1);

	if (choice == 1) {
		inc_flag(13,0,3);
		inc_flag(13,1,1);
		inc_flag(13,7,1);
		swap_terrain(5,34,374,375);
		play_sound(76);
}

break;

 beginstate 13;
	reset_dialog();
	add_dialog_str(0,"You find a blank lever. It's purpose is a mystery, yet, there is no harm in pulling it.",0);
	add_dialog_choice(0,"Pull the Lever.");
	add_dialog_choice(1,"Ignore it.");
	choice = run_dialog(1);

	if (choice == 1) {
		set_flag(13,0,0);
		set_flag(13,1,0);
		swap_terrain(6,32,374,375);
		play_sound(76);
}
break;

 beginstate 14;
	if (get_flag(13,4) == 0) {
		message_dialog("You quickly turn around. The wall has moved back to its original place. You're trapped. Hopefully you can find a way to reopen the wall.","");
		play_sound(45);
		set_terrain(9,31,40);
		force_instant_terrain_redraw();
		set_flag(13,4,2);
}
	if (get_flag(13,4) == 1) {
		play_sound(45);
		set_terrain(9,31,40);
		set_flag(13,4,2);
		force_instant_terrain_redraw();
}
break;

 beginstate 15;
	reset_dialog();
	add_dialog_str(0,"You find yet another lever. This time though, you know what it does. It slides the wall so that you may leave the caves.",0);
	add_dialog_choice(0,"Pull the Lever.");
	add_dialog_choice(1,"Ignore it.");
	choice = run_dialog(1);

	if (choice == 1) {
		swap_terrain(19,25,374,375);
		play_sound(76);
		set_terrain(9,31,0);
}
break;

 beginstate 16;
	if (get_flag(13,3) == 0) {
		message_dialog("You figured there were some kind of creatures in these caves when you saw the light at the end of the hallway. Now you are positive that the creatures are human. One of them is pointing a crossbow at your face.","");
		set_flag(13,3,1);
		begin_talk_mode(1);
}
break;

 beginstate 17;
	if (get_flag(13,5) == 3) {
		message_dialog("The man raises his crossbow again. _I sure as hell warned you not to take a step closer!_ He fires a shot at you, worthy of a marksman.","");
		set_flag(13,5,5);
		damage_char(0,170,0);
		make_town_hostile();
}
break;

 beginstate 18;
	if (get_flag(13,8) == 0) {
		message_dialog("You take your first look at the bulk of the rebels. These ragtag men cannot possibly be threat to the Empire. Even if you think of them as bandits they are pathetic, and judging by their faces, they know this too.","");
		set_flag(13,8,1);
}
 break;

 beginstate 19;
	if ((get_flag(13,5) == 5) && (get_flag(13,10) == 0)) {
		reset_dialog();
		add_dialog_str(0,"The man in the cave ahead raises his arms and shouts. _Hear me out ye dogs! Ye don't want to kill me I know things!_ What say you?",0);
		add_dialog_choice(0,"You know nothing that interests me, die!");
		add_dialog_choice(1,"Tell me! Maybe I'll let you live.");
		choice = run_dialog(1);
}
	if (choice == 2) {
		set_attitude(8,3);
		begin_talk_mode(26);
		set_flag(13,10,1);
}
 break;

 beginstate 20;
	block_entry(1);
	reset_dialog();
	add_dialog_str(0,"This seems like a quiet enough spot. It's got free sleeping pads and a camp fire. You could rest here for a few hours, if you wanted to.",0);
	add_dialog_choice(0,"Sleep.");
	add_dialog_choice(1,"Move along.");
	choice = run_dialog(1);
	
	if (choice == 1)
		set_state_continue(21);
 break;

 beginstate 21;
	revive_party();
	set_ticks_forward(100);

	if (has_special_item(5)) {
		relocate_character(0,30,12);
		relocate_character(1,31,11);
		relocate_character(2,32,11);
		relocate_character(3,33,12);
		relocate_character(10,30,15);
		relocate_character(15,32,15);
		relocate_character(11,34,14);
		relocate_character(12,29,13);
		relocate_character(13,28,13);
		relocate_character(14,29,15);
		relocate_character(9,29,17);
		relocate_character(8,30,16);
		relocate_character(7,31,15);
		relocate_character(6,32,16);
		set_flag(13,6,2);
		reset_dialog();
		add_dialog_str(0,"You wake up, when someone kicks you in the side. Opening your eyes you see the mercenary at the cave entrance, smiling innocently and holding up your deputation papers. _Care to explain?_ He asks cheerfully. The rebels are all around him.",0);
		add_dialog_choice(0,"We stole that.");
		add_dialog_choice(1,"Sure, die scum!");
		choice = run_dialog(1);
		make_town_hostile();
	if (choice == 1)
		message_dialog("Vitendo cries out _No ye didn't, ye lying scum! Men kill the pigs!_","");
}
 break;

 beginstate 22;
	if ((get_flag(17,17) >= 2) && (get_flag(17,9) == 1) && (get_flag(13,20) == 0)) {
		message_dialog("The rebels have left the caves. They dreamed of an Empire-free Faerengrove and caused unspeakable damage while trying to fulfill that dream.","They paid the most dearest price for their stupidity.");
		set_flag(13,20,1);
}
 break;